import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    server: {
        port: 3009,
        open: true, // 服务启动时是否自动打开浏览器
        cors: true, // 允许跨域
        proxy: {
            '/api': {
                target: 'http://localhost:3008',
                changeOrigin: true,
                secure: false,
                rewrite: path => path.replace(/^X/, ''),
            }
        },
    },
    resolve: {
        alias: {
            '@': resolve(__dirname, './src'),
        },
        extensions: ['.js', '.json', '.ts', '.tsx'],
    },
    plugins: [react(), legacy({
        targets: ['Chrome 63'],
        additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
        modernPolyfills: true
    })],
    build: {
        target: 'es2015'
    }
})
